<!--
 * @Author: wangming
 * @Date: 2021-05-29 15:44:34
 * @LastEditors: wangming
 * @LastEditTime: 2022-04-14 15:08:31
 * @Description: 模态框可选列表
-->
<template>
  <div>
    <el-form-item label="可选列表类型" class="tr">
      <el-radio-group v-model="value.listType">
        <el-radio label="Stable">表格</el-radio>
        <el-radio label="Slist">列表</el-radio>
      </el-radio-group>
    </el-form-item>
    <div v-if="value.listType === 'Stable'">
      <el-form-item label="开启搜索" class="tr">
        <el-switch v-model="value.__config.openSearch"> </el-switch>
      </el-form-item>
      <div class="mb10 pl5 ks-row-between">
        <div>表头字段</div>
        <el-checkbox :value="allbox" @input="changeall">全选</el-checkbox>
      </div>
      <draggable
        handle=".mover"
        :animation="200"
        :list="tabledata"
        :delay="20"
        chosen-class="drawing-chosen"
        drag-class="drawing-drag"
      >
        <div
          v-for="(i, index) in tabledata"
          :key="index"
          class="ks-row-middle-between mb5 pl5 pr5"
        >
          <el-checkbox
            v-model="i.showColumn"
            class="ks-col"
            :disabled="
              value.__config.getEntitymodelList.length === 1 && i.showColumn
            "
            >{{ i.name }}
          </el-checkbox>
          <i class="el-icon-rank mover poi"></i>
        </div>
      </draggable>
    </div>
  </div>
</template>

<script>
import { uuid } from "@/utils/common.js";
import draggable from "vuedraggable";
import basicmixins from "../basicmixins";
export default {
  computed: {
    allbox() {
      return this.tabledata.every((i) => i.showColumn);
    },
  },
  components: { draggable },
  mixins: [basicmixins],
  watch: {
    "value.__config.openSearch"(val) {
      if (val) {
        if (!this.value.__config.searchConfig) {
          this.$set(this.value.__config, "searchConfig", {
            name: "搜索",
            tagName: "hlSearch", // 标签名称
            childrens: [], // 条件查询
            key: uuid(),
            __config: {
              singleQuantity: 2, // 单行显示数量  2 3 4 0（自定义）
              singleQuantityCustom: 1, // 单行显示数量 自定义
            },
          });
        } else {
          this.value.__config.searchConfig.__config.modelCode !=
            this.value.__config.modelCode &&
            (this.value.__config.searchConfig.childrens = []);
        }
        this.value.__config.searchConfig.__config.modelCode =
          this.value.__config.modelCode;
      }
    },
  },
  created() {
    this.tabledata = this.value.__config.getEntitymodelList;
    if (this.value.__config.openSearch && this.value.__config.searchConfig) {
      this.value.__config.searchConfig.__config.modelCode !=
        this.value.__config.modelCode &&
        (this.value.__config.searchConfig.childrens = []);
      this.value.__config.searchConfig.__config.modelCode =
        this.value.__config.modelCode;
    }
  },
  data() {
    return {
      tabledata: [],
    };
  },
  methods: {
    changeall(v) {
      this.tabledata.forEach((i) => {
        i.showColumn = v;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.mover {
  color: #409eff;
}
</style>
